package com.taiji.dicom4platform.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.util.StringUtil;
import com.taiji.dicom4platform.admin.service.SysConfigService;
import com.taiji.dicom4platform.common.core.utils.R;
import com.taiji.dicom4platform.common.log.annotation.SnowLog;
import com.taiji.dicom4platform.common.model.entity.SysConfig;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName SysConfigController
 * @Description
 * @Author HX
 * @Date 2021/8/11 11:28
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("/config")
@Api(value = "config", tags = "系统配置")
public class SysConfigController {


    private final SysConfigService sysConfigService;
    /**
     * 分页查询字典信息
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    public R<IPage> getConifgPage(Page page, SysConfig sysConfig) {
        return R.ok(sysConfigService.page(page, Wrappers.<SysConfig>lambdaQuery()
                .like(StringUtil.isNotEmpty(sysConfig.getConfigName()),SysConfig::getConfigName,sysConfig.getConfigName())));
    }


    @SnowLog("添加参数")
    @PostMapping
    public R save(@Valid @RequestBody SysConfig sysConfig) {
        return R.ok(sysConfigService.saveOrUpdate(sysConfig));
    }


    @GetMapping("/keys")
    public R getConfigByKeys(@RequestParam("configKeys") String configKeys){
        return R.ok(sysConfigService.getConfigByKeys(configKeys));
    }
}
